package com.mall.dao;

import com.mall.domain.Address;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IAddressDao {
	//	查找全部地址
	//	@Results(id = "addressMap")
	//	@ResultMap("addressMap")
	@Select("select * from tb_address where flag=0")
	List<Address> findAllAddress();

	// 查看地址
	//	@Results(id = "addressMap1")
	@Select("select * from tb_address where id=#{id}")
	List<Address> findAddressById(@Param("id") Integer id);

	//	修改地址
	//	@Results(id = "addressMap2")
	@Update("update tb_address set name=#{newAddress.name},tel=#{newAddress.tel}," +
			"address=#{newAddress.address} where id=#{newAddress.id}")
	Integer updateAddress(@Param("newAddress") Address address);

	//  删除地址 :将flag设为1
	@Update("update tb_address set flag=1 where id=#{id}")
	Integer deleteAddress(@Param("id") Integer id);

	//新增地址
	@Insert("INSERT INTO tb_address (name,tel,address) VALUES(#{address.name},#{address.tel},#{address.address})")
	Integer addAddress(@Param("address") Address address);
}
